                            <? $frmtime = time(); ?>
                            <div class="main" style="position: relative;">
                                <div id="modal<?=$frmtime?>" style="display: none; position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; background: rgba(245, 242, 234, 0.5);">
                                    <div style="width: 250px; margin: 150px auto;"><strong>Processing</strong><br/><img src="/images/ajaxloader.gif" /></div>
                                </div>
                                <h3 class="title"><?=$clabel?> &raquo; <?=$mlabel?></h3>
                                <div class="formdiv">
                                    <form method="POST" id="frmNewReceipt">
                                        <table border="0">
                                            <? if( isset($errors) ) {
                                               foreach($errors as $error) {
                                               ?>
                                            <tr>
                                                <td class="errormsg" colspan="3">
                                                    <?=$error?>    
                                                </td>
                                            </tr>   
                                               <? 
                                               } 
                                            }  ?>
                                            <? if( isset($successes) ) {
                                               foreach($successes as $success) {
                                               ?>
                                            <tr>
                                                <td class="successmsg" colspan="3">
                                                    <?=$success?>    
                                                </td>
                                            </tr>   
                                               <? 
                                               } 
                                            }  ?>
                                            <tr>
                                                <td colspan="3">
                                                    <div style="text-align: center; min-width: 700px;">
                                                        <label style="padding: 0;">Register No.</label>
                                                        <input type="text" class="stext" id="student_regno_<?=$frmtime?>" name="student_regno" value="<?=$postdata['student_regno']?>" />
                                                        <input class="button" style="float: none;" type="button" name="btnSearch" value="Search" id="btnSearchRegNo_<?=$frmtime?>" />
                                                        <label style="padding: 0;" for="receipt_is_general">General Receipt</label>
                                                        <input type="checkbox" id="receipt_is_general" name="receipt_is_general" value="1" <? echo ($postdata['receipt_is_general']==1) ? "checked" : ""; ?> />
                                                    </div>
                                                    <div id="div_receipt_error_<?=$frmtime?>" style="text-align: center; margin-top: 5px; color: red;" ></div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="3">
                                                    <div style="text-align: center; min-width: 700px; padding-top: 10px;">
                                                        <label style="font-size: 22px; font-weight: bold;">Receipt</label>
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="3">
                                                    <div style="text-align: center; padding: 10px 0 10px 0; border-top: 3px solid gray;  border-bottom: 3px solid gray;">
                                                        <table width="100%">
                                                            <tr>
                                                                <td style="text-align: center;">
                                                                    <label style="padding: 0;">Term:</label><br />
                                                                    <select style="height: 28px;" class="stext required" name="receipt_term">
                                                                        <option value="">-- Select --</option>
                                                                        <?
                                                                            if(isset($termlist) && is_array($termlist) && count($termlist) > 0) {
                                            	                               foreach( $termlist as $term ) {
                                            	                                   $sel = '';
                                            	                                   if(isset($postdata["receipt_term"]) && $term["term_id]"].'-'.$term["term_year]"]==$postdata["receipt_term"]) { $sel = "selected"; }
                                                                                   if($postdata["receipt_term"] == '' && $term['term_now'] == 1 ) { $sel = "selected"; }
                                                                                   $term_value = $term["term_id"].'-'.$term["term_year"];
                                                                        ?>
                                                                                <option value="<?=$term_value?>" <?=$sel?>><?=$term["term_label"]?></option>
                                                                        <?
                                            	                           }
                                                                        }
                                                                        ?>
                                                                    </select>
                                                                </td>
                                                                <td style="text-align: center;">
                                                                    <label style="padding: 0;">Register No:</label>
                                                                    <div class="stext" style="margin: 0 auto;" id="div_receipt_regno_<?=$frmtime?>"><?=$postdata['receipt_regno']?></div>
                                                                    <input type="hidden" class="" id="receipt_regno_<?=$frmtime?>" name="receipt_regno" value="<?=$postdata['receipt_regno']?>" />
                                                                </td>
                                                                <td style="text-align: center;">
                                                                    <label style="padding: 0;">Name:</label>
                                                                    <input type="text" style="display: block; margin: 0 auto;" readonly="true" class="text" name="receipt_student_name" id="receipt_name_<?=$frmtime?>" value="<?=$student_name?>" />
                                                                </td>
                                                                <td>
                                                                    <label style="padding: 0;">Class:</label>
                                                                    <div class="stext" style="margin: 0 auto;" id="div_receipt_class_<?=$frmtime?>"><?=$class_label?></div>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="3">
                                                    <table class="tbl-receipt">
                                                        <tr>
                                                            <td width="60px"><label style="padding: 0;">Si. No.</label></td>
                                                            <td><label style="padding: 0;">Item/Category</label></td>
                                                            <td><label style="padding: 0;">Description</label></td>
                                                            <td><label style="padding: 0; float: right;">Amount (QR)</label></td>
                                                        </tr>
                                                    <?
                                                    for($rc=0; $rc< $fee_item_rows; $rc++) {
                                                    ?>
                                                    <tr>
                                                        <td><label style="padding: 0;"><?=$rc+1?></label></td>
                                                        <td>
                                                            <select class="text required" name="ri_feetype[]">
                                                                <option value="">-- Select --</option>
                                                                <?
                                                                    if(isset($feetypelist) && is_array($feetypelist) && count($feetypelist) > 0) {
                                    	                               foreach( $feetypelist as $feetypeitem ) {
                                    	                                   $sel = '';
                                    	                                   if(isset($postdata["ri_feetype"][$rc]) && $feetypeitem["feetype_id"]==$postdata["ri_feetype"][$rc]) { $sel = "selected"; }
                                                                ?>
                                                                        <option value="<?=$feetypeitem["feetype_id"]?>" <?=$sel?>><?=$feetypeitem["feetype_label"]?></option>
                                                                <?
                                    	                           }
                                                                }
                                                                ?>
                                                            </select>
                                                        </td>
                                                        <td>
                                                            <input type="text" class="text" maxlength="100" name="ri_description[]" value="<?=$postdata['ri_description'][$rc]?>" />
                                                        </td>
                                                        <td>
                                                            <input type="text" style="text-align: right;" class="stext required" maxlength="8" name="ri_amount[]" value="<?=$postdata['ri_amount'][$rc]?>" />
                                                        </td>
                                                    </tr>
                                                    <?
                                                    }                                            
                                                    ?>
                                                    <tr>
                                                        <td>
                                                            <label style="padding: 0; float: Left;">Comment:</label>
                                                        </td>
                                                        <td>
                                                            <input type="text" style="text-align: left; float: left;" class="text" maxlength="250" name="receipt_comment" value="<?=$postdata['receipt_comment']?>" />
                                                        </td>
                                                        <td><label style="padding: 0; float: right;">Discount:</label></td>
                                                        <td>
                                                            <input type="text" style="text-align: right; float: right;" class="stext" maxlength="6" id="receipt_discount_<?=$frmtime?>" name="receipt_discount" value="<?=$postdata['receipt_discount']?>" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td colspan="3"><label style="font-size: 22px; padding: 0; float: right;">Total:</label></td>
                                                        <td>
                                                            <label style="font-size: 22px; padding: 0; float: right;">QR 
                                                            <span style="font-size: 22px; padding: 0; color: #3E3E3E;" id="receipt_total_<?=$frmtime?>"><?=$receipt_total?></span></label>
                                                        </td>
                                                    </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                            
                                            <tr>
                                                <td colspan="3"><div style="margin-top: 10px;"></div></td>
                                            </tr>
                                        	<tr>
                                        		<td>&nbsp;</td>
                                        		<td colspan="2">
                                                    <span style="float: right;">
                                                    <input class="button" type="submit" name="btnSaveReceipt" value="Save" id="btnSaveReceipt" />
                                                    <input class="button" type="reset" value="Cancel" id="btnreset" />
                                                    </span>
                                                </td>
                                        	</tr>
                                        </table>
                                	</form>
                                    <script language="javascript" type="text/javascript">
                                        if(typeof jQuery == 'undefined') {
                                            alert('Invalid Request');
                                            window.location = "/";
                                        }
                                        function roundNumber(number, decimals) { // Arguments: number to round, number of decimal places
                                        	var newnumber = new Number(number+'').toFixed(parseInt(decimals));
                                        	return  parseFloat(newnumber); // Output the result to the form field (change for your purposes)
                                        }
                                        function calculateTotal() {
                                            var receipt_total = 0.00;
                                            $("#frmNewReceipt input[name^=ri_amount]").each(function() {
                                                var ival = $.trim($(this).val());
                                                if(ival!="" && !isNaN(ival)) {
                                                    receipt_total += roundNumber(parseFloat(ival),2);
                                                } else {
                                                    if(ival!="") {
                                                        alert("Enter a valid amount.");
                                                        $(this).val("");
                                                    }
                                                }
                                            });
                                            var discount = $.trim($("#receipt_discount_<?=$frmtime?>").val());
                                            if(discount!="" && !isNaN(discount)) {
                                                receipt_total -= roundNumber(parseFloat(discount),2);
                                            } else {
                                                if(discount!="") {
                                                    alert("Enter a valid amount.");
                                                    $(this).val("");
                                                }
                                            }
                                            var round_total = roundNumber(receipt_total,2);
                                            $("#receipt_total_<?=$frmtime?>").html(round_total);
                                            $("#rtotal_<?=$frmtime?>").html(round_total);
                                        }
                                        $(document).ready( function() {
                                            $("#btnSearchRegNo_<?=$frmtime?>").click(function() {
                                                var reg_no = $("#student_regno_<?=$frmtime?>").val();
                                                if(reg_no!="") {
                                                    $("#div_receipt_error_<?=$frmtime?> ").html('');
                                                    var jqxhr = jQuery.getJSON(
                                                        "/student/getstudent/"+reg_no+"?json=1",
                                                        function (data) {
                                                            $("#modal<?=$frmtime?>").hide(); 
                                                            if(data.status != 0) {
                                                                $('#frmNewReceipt label.error').remove();
                                                                $("#frmNewReceipt")[0].reset();
                                                                $("#receipt_regno_<?=$frmtime?>").val(data.result.reg_no);
                                                                $("#receipt_regno_<?=$frmtime?>").data('feedata',data.result.feedata);
                                                                $("#lblRegNo_<?=$frmtime?>").html(data.result.reg_no);
                                                                $("#div_receipt_regno_<?=$frmtime?> ").html(data.result.reg_no); 
                                                                $("#receipt_name_<?=$frmtime?> ").val(data.result.student_name);
                                                                $("#lblName_<?=$frmtime?> ").html(data.result.student_name);
                                                                $("#div_receipt_class_<?=$frmtime?> ").html(data.result.class_label);
                                                                $("#lblClass_<?=$frmtime?> ").html(data.result.class_label);
                                                                $("#receipt_total_<?=$frmtime?>").html("0.00");
                                                                $("#rtotal_<?=$frmtime?>").html("");
                                                                          
                                                            } else {
                                                                $('#frmNewReceipt label.error').remove();
                                                                $("#frmNewReceipt")[0].reset();
                                                                $("#div_receipt_error_<?=$frmtime?> ").html(data.error);
                                                                $("#receipt_regno_<?=$frmtime?>").val("");
                                                                $("#receipt_regno_<?=$frmtime?>").data('feedata','');
                                                                $("#lblRegNo_<?=$frmtime?>").html("");
                                                                $("#div_receipt_regno_<?=$frmtime?> ").html(""); 
                                                                $("#receipt_name_<?=$frmtime?> ").val("");
                                                                $("#lblName_<?=$frmtime?> ").html("");
                                                                $("#div_receipt_class_<?=$frmtime?> ").html("");
                                                                $("#lblClass_<?=$frmtime?> ").html("");
                                                                $("#receipt_total_<?=$frmtime?>").html("0.00");
                                                                $("#rtotal_<?=$frmtime?>").html("");
                                                            }
                                                        }
                                                    );
                                                    $("#modal<?=$frmtime?>").show();
                                                } else {
                                                    $("#div_receipt_error_<?=$frmtime?> ").html('Enter a valid Reg. No.'); 
                                                    $("#student_regno_<?=$frmtime?>").focus();
                                                }
                                                
                                            });
                                            
                                            var $rcdialog = $("#cnfreceipt").dialog({ 
                                                autoOpen: false, 
                                                title: 'Confirm',
                                                resizable: false,
                                                width: 500,
                                                modal: true,
                                                buttons : {
                                                    "Ok": function() {
                                                        var cui = $('#contenttabs .ui-tabs-panel:visible');                                                                                                        
                                                   	    var jqxhr = $.post(
                                                            "/fees/newreceipt", 
                                                            $("#frmNewReceipt").serialize(), 
                                                            function (data) {
                                                                $(cui).html(data);
                                                            }
                                                        );
                                                        $(cui).html('<div id="loadingdiv"><div class="centerdiv"><strong>Processing</strong><br/><img src="/images/ajaxloader.gif" /></div></div>');
                                                    
                                                        $(this).dialog( "close" );
                                                    },
                                                    "Cancel": function() {
                                                        $( this ).dialog( "close" );
                                                    }
                                                } 
                                            });
                                            
                                            $("#frmNewReceipt input[name^=ri_amount]").change(calculateTotal);
                                            $("#receipt_discount_<?=$frmtime?>").change(calculateTotal);
                                            $("#frmNewReceipt input[name^=ri_amount]").blur(calculateTotal);
                                            $("#receipt_discount_<?=$frmtime?>").blur(calculateTotal);
                                            $("#frmNewReceipt").validate({
                                                rules: {
                                                    receipt_regno: {
                                                        required: {
                                                            depends: function() {
                                                                var is_echecked = $("#receipt_is_general").is(":checked") ? false : true;
                                                                return is_echecked;
                                                            }
                                                        }
                                                    },
                                                    receipt_student_name: {
                                                        required: {
                                                            depends: function() {
                                                                var is_echecked = $("#receipt_is_general").is(":checked") ? true : false;
                                                                return is_echecked;
                                                            }
                                                        }
                                                    }
                                                },
                                                errorPlacement: function(error, element) {
                                                    var errorplace = element.parent();
                                                    error.appendTo(errorplace.append("<div></div>"));
                                                },
                                                submitHandler: function(form) {
                                                        var is_echecked = $("#receipt_is_general").is(":checked") ? true : false;
                                                        if(is_echecked) {
                                                            $("#lblName_<?=$frmtime?> ").html($("#receipt_name_<?=$frmtime?> ").val());
                                                            $("#lblRegNo_<?=$frmtime?>").html("");
                                                            $("#lblClass_<?=$frmtime?>").html("");
                                                        }
                                                        $rcdialog.dialog('open');
                                                    }
                                            });
                                            $("#frmNewReceipt input[type='reset']").click( function() {
                                                reset_form();
                                            });
                                            
                                            $("#frmNewReceipt select[name^=ri_feetype]").change(function(){
                                                $feedata = $("#receipt_regno_<?=$frmtime?>").data('feedata');                                                
                                                $feetype = $(this).val();
                                                console.log($feetype);
                                                $parent_tr = $(this).closest("tr");
                                                if(typeof $feedata == 'object' && typeof $feedata[$feetype] != "undefined") {
                                                    $("input[name^=ri_amount]",$parent_tr).val($feedata[$feetype]);
                                                } else {
                                                    $("input[name^=ri_amount]",$parent_tr).val('');
                                                }
                                                calculateTotal();
                                            });
                                            
                                            $("#receipt_is_general").change(function(){ 
                                                reset_form();                                               
                                                if($(this).is(":checked")) {
                                                    $("#receipt_name_<?=$frmtime?> ").attr("readonly",false);
                                                    $("#receipt_name_<?=$frmtime?> ").focus();
                                                } else {
                                                    $("#receipt_name_<?=$frmtime?> ").attr("readonly",true);
                                                }
                                            });
                                            
                                            function reset_form() {
                                                $('#frmNewReceipt label.error').remove();
                                                $("#receipt_regno_<?=$frmtime?>").val("");
                                                $("#receipt_regno_<?=$frmtime?>").data('feedata','');
                                                $("#div_receipt_regno_<?=$frmtime?> ").html(""); 
                                                $("#receipt_name_<?=$frmtime?> ").val("");
                                                $("#div_receipt_class_<?=$frmtime?> ").html("");
                                                $("#receipt_total_<?=$frmtime?>").html("0.00");
                                            }
                                        });
                                    </script>
                                 </div>
                                 <div id="cnfreceipt" style="display: none;">
                                    <h3>Receipt</h3>
                                    <table width="100%" cellpadding="3">
                                        <tr>
                                            <td width="100"><label>Register No:</label></td>
                                            <td><label>Name:</label></td>
                                            <td width="160"><label>Class:</label></td>
                                        </tr>
                                        <tr>
                                            <td><label id="lblRegNo_<?=$frmtime?>"><?=$postdata['receipt_regno']?></label></td>
                                            <td><label id="lblName_<?=$frmtime?>"><?=$student_name?></label></td>
                                            <td><label id="lblClass_<?=$frmtime?>"><?=$class_label?></label></td>
                                        </tr>
                                        <tr>
                                            <td colspan="2"><label style="font-size: 22px;">Total</label></td>
                                            <td><label style="font-size: 22px;" id="rtotal_<?=$frmtime?>"><?=$receipt_total?></label></td>
                                        </tr>
                                    </table>
                                 </div>
                            </div>